<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Http\Controllers;

use App\Exceptions\ApiException;
use App\Services\EnumDbService;
use Illuminate\Http\Request;

class EnumDbController extends Controller
{
    protected $enumDbService;

    public function __construct(EnumDbService $enumDbService)
    {
        $this->enumDbService = $enumDbService;
    }

    public function createIndustry(Request $request)
    {
        $title = $request->input('title');
        if (empty($title)) {
            throw new ApiException('参数错误', 1);
        }
        $this->enumDbService->createIndustry($title);
        return renderSuccessJson();
    }

    public function updateIndustry(Request $request)
    {
        $title = $request->input('title');
        $id = $request->input('id');
        if (empty($id) || empty($title)) {
            throw new ApiException('参数错误', 1);
        }
        $this->enumDbService->updateIndustry($id, $title);
        return renderSuccessJson();
    }

    public function deleteIndustry(Request $request)
    {
        $id = $request->input('id');
        if (empty($id)) {
            throw new ApiException('参数错误', 1);
        }
        $this->enumDbService->deleteIndustry($id);
        return renderSuccessJson();
    }
}
